Shared strings do not have tail-allocated storage, but can provide access upon query to contiguous UTF-8 code units. Lazily-bridged NSStrings capable of providing access to contiguous ASCII/UTF-8 set the ObjC bit. Accessing shared string's pointer should always be behind a resilience barrier, permitting future evolution.

字符串数据没有从内部_object处起始,但是可以获取连续的 utf-8 code unit。
对应的类是__SharedStringStorage

内存布局

在 OC runtime下,是 NSString 子类

子类化 NSString

#if _runtime(_ObjC)

  @objc(length)
final internal var length: Int {
@_effects(readonly) get {
return asString.utf16.count // UTF16View special-cases ASCII for us.
}
}
  @objc(characterAtIndex:)
@_effects(readonly)
final internal func character(at offset: Int) -> UInt16 {
let str = asString
return str.utf16[str._toUTF16Index(offset)]
} @objc(getCharacters:range:)
@_effects(releasenone)
final internal func getCharacters(
_ buffer: UnsafeMutablePointer<UInt16>, range aRange: _SwiftNSRange
) {
_getCharacters(buffer, aRange)
}

Swift里字符串(六)Shared strings的更多相关文章

  1. Swift 里字符串(四)large sting

    对于普通的字符串,对应的_StringObject 有两个存储属性: _countAndFlagsBits: UInt64 _object: Builtin.BridgeObject _countAn ...

  2. Swift 里字符串(一)概览

    感受一下字符串相关的源文件个数  String 概览 是一个结构体 只有一个变量,类型是 _StringGuts  如上所示,String 真正的内容在__StringStorage或者__Sha ...

  3. Swift里字符串(五)Native strings

    Native strings have tail-allocated storage, which begins at an offset of nativeBias from the storage ...

  4. Swift 里字符串(十)修改字符串

    以append操作为例 public mutating func append(_ other: String) { if self.isEmpty && !_guts.hasNati ...

  5. [Swift]LeetCode43. 字符串相乘 | Multiply Strings

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1and  ...

  6. Swift 里字符串(七)stringIndex

    在 String 里,用来索引 Character 的,不是整数,而是StringIndex 内部结构 extension String { /// A position of a character ...

  7. Swift 里字符串(三)small String

     small string, 只有两个 UInt64 的字,这里面存储了所有的信息. 内存布局如下:  第二个 UInt64 存储了标记位和长度信息,以及部分字符串的值 // Get an int ...

  8. [Swift]LeetCode415. 字符串相加 | Add Strings

    Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...

  9. Swift 里字符串(十一)OC 字符串和 Swift 字符串的转换

     to OC func _bridgeToObjectiveCImpl() -> AnyObject { if _guts.isSmall { return _guts.asSmall.wit ...

随机推荐

  1. 在命令提示符(cmd)下怎样复制粘贴

      我们把鼠标放在面板的上方,右击,界面显示如下:   我们选择“属性”,单击,界面显示如下:   我们点选“快速编辑模式”,再点击“确定”,这样设置就完成了,界面显示如下:   我们在面板中随意选择 ...

  2. 551. Student Attendance Record I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  3. Django入门与实践-第12章:复用模板(完结)

    http://127.0.0.1:8000/http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1 ...

  4. SQL之经典SQL语句大全

    经典SQL语句大全 一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql serv ...

  5. 字符串转换成NSDate类型的 为nil解决方法

    方法一    通过下列函数来解决   但是得到的日期会改变 修改方法fix   - (NSDate *)timeForString:(NSString *)string {         NSMut ...

  6. C++和Python混合编程

    为何人工智能(AI)首选Python?读完这篇文章你就知道了:https://blog.csdn.net/qq_41769259/article/details/79419322 C++调用Pytho ...

  7. (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087

    http://acm.hdu.edu.cn/showproblem.php?pid=1087   Super Jumping! Jumping! Jumping! Time Limit:1000MS  ...

  8. hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...

  10. shell 脚本,将/etc/目录下所有的软链接文件输出

    #!/bin/bash # cd /etc for a in *;do if [ -L $a ];then #如果文件存在,为软链接文件且指向的是文件,则返回真 echo $a fi done 测试: